﻿using CloudSharingStation_UWP_.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x804 上介绍了“空白页”项模板

namespace CloudSharingStation_UWP_
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        private ResourceList resourceList = null;
        public MainPage()
        {
            this.InitializeComponent();
            Nav.Header = "检索文件";
        }

        private void Nav_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
        {
            if (args.IsSettingsSelected)
            {
                sender.Header = "设置";
                contentFrame.Navigate(typeof(SettingPage));
            }
            else
            {
                var selectItem = (Windows.UI.Xaml.Controls.NavigationViewItem)args.SelectedItem;
                if (selectItem!=null)
                {
                    string content = (string)selectItem.Content;
                    sender.Header = content;
                    switch(content)
                    {
                        case "检索文件":contentFrame.Navigate(typeof(SearchPage),resourceList);break;
                        case "上传列表":contentFrame.Navigate(typeof(UploadPage), resourceList);break;
                        case "下载列表":contentFrame.Navigate(typeof(DownloadPage), resourceList);break;
                        case "我的收藏":contentFrame.Navigate(typeof(FavoritePage), resourceList);break;
                        default:break;
                    }
                }
            }
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            resourceList =(ResourceList) e.Parameter;
            contentFrame.Navigate(typeof(SearchPage), resourceList);
        }
    }
}
